package com.yanqu.road.server.manager.tomb.entity;

import com.yanqu.road.dao.dbV2.BaseEntity;
import com.yanqu.road.dao.dbV2.IField;
import com.yanqu.road.dao.dbV2.ITable;
import com.yanqu.road.dao.dbV2.serializer.*;
import com.yanqu.road.logic.activity.tomb.config.entity.ActivityTombConfig;
import com.yanqu.road.pb.tomb.Tomb;
import com.yanqu.road.server.manager.tomb.TombActivity;
import com.yanqu.road.server.manager.tomb.TombServiceMgr;
import com.yanqu.road.utils.date.DateHelper;


import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

@ITable(tableName = "t_c_activity_tomb_user")
public class DbTombUser extends BaseEntity {
    public static DbTombUser newInstance() {
        return new DbTombUser();
    }

    @IField(isPrimaryKey = true, fieldName = "activity_id", comment = "活动ID", serializer = DInt.class)
    public int activityId;
    @IField(isPrimaryKey = true, fieldName = "user_id", comment = "用户ID", serializer = DLong.class)
    public long userId;

    @IField(fieldName = "partner_info_map", comment = "伙伴列表", serializer = DObject.class)
    public Map<Integer, PartnerInfo> partnerInfoMap = new ConcurrentHashMap<>();

    @IField(fieldName = "partner_upgrade_info_map", comment = "伙伴升级信息", serializer = DObject.class)
    public Map<Integer, PartnerUpgradeInfo> partnerUpgradeInfoMap = new ConcurrentHashMap<>();

    @IField(fieldName = "floor", comment = "当前层数", serializer = DInt.class)
    public int floor;

    @IField(fieldName = "x", serializer = DInt.class)
    public int x;
    @IField(fieldName = "y", serializer = DInt.class)
    public int y;

    @IField(fieldName = "energy", serializer = DInt.class)
    public int energy;

    @IField(fieldName = "cost_energy", serializer = DInt.class)
    public int costEnergy;

    @IField(fieldName = "energy_update_time", serializer = DDateTime.class)
    public long energyUpdateTime = 0;

    @IField(fieldName = "hp", serializer = DLong.class)
    public long hp;
    @IField(fieldName = "max_hp", serializer = DLong.class)
    public long maxHp;

    @IField(fieldName = "status", comment = "玩家当前状态", serializer = DInt.class)
    public int status; //0正常情况  1 冻住  2 死亡

    @IField(fieldName = "attack_user_id", comment = "攻击人ID", serializer = DLong.class)
    public long attackUserId;
    @IField(fieldName = "reward_score", comment = "悬赏分", serializer = DInt.class)
    public int rewardScore;

    @IField(fieldName = "pvp_chose_num", comment = "pvp事件被选中次数", serializer = DInt.class)
    public int pvpChoseNum;


    @IField(fieldName = "user_info", comment = "用户基本信息", serializer = DObject.class)
    public UserInfo userInfo = new UserInfo();

    @IField(fieldName = "go_downstairs", comment = "正要进入下一层", serializer = DInt.class)
    public int goDownstairs;


    @IField(fieldName = "score", comment = "玩家积分", serializer = DLong.class)
    public long score;

    @IField(fieldName = "union_score", comment = "玩家商会积分", serializer = DLong.class)
    public long unionScore;
    @IField(fieldName = "multi_kill", comment = "连杀数", serializer = DInt.class)

    public int multiKill;

    @IField(fieldName = "user_niantu_num", comment = "用户使用的黏土个数", serializer = DLong.class)
    public long userNianTuNum;

    @IField(fieldName = "lock_event", comment = "当前锁定的事件", serializer = DString.class)
    public String lockEvent = "";

    @IField(fieldName = "doll_map", comment = "拥有人偶", serializer = DObject.class)
    public Map<Integer, Long> dollMap = new ConcurrentHashMap<>();

    @IField(fieldName = "choose_doll", comment = "当前使用人偶", serializer = DInt.class)
    public int dollId;

    @IField(fieldName = "pvp_union_choose_map", comment = "PVP被选的商会", serializer = DObject.class)
    public Set<String> pvpUnionChooseMap = new HashSet<>();

    @IField(fieldName = "attack_addition", comment = "攻击加成", serializer = DInt.class)
    public int attackAddition;

    @IField(fieldName = "hp_addition", comment = "技能加成", serializer = DInt.class)
    public int hpAddition;

    @IField(fieldName = "switch", comment = "开关", serializer = DObject.class)
    public List<Integer> switchList = new ArrayList<>();

    @IField(fieldName = "guide_mark", comment = "是否引导", serializer = DInt.class)
    public int guideMark;

    @IField(fieldName = "groupId", serializer = DInt.class)
    public int groupId;

    /**
     * 已经协助攻击的次数
     */
    private int assistTimes;

    /**
     * 玩家已经探索的事件
     */
    private int exploredNum;

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public Map<Integer, PartnerInfo> getPartnerInfoMap() {
        return partnerInfoMap;
    }

    public void setPartnerInfoMap(Map<Integer, PartnerInfo> partnerInfoMap) {
        this.partnerInfoMap = partnerInfoMap;
    }

    public void addPartnerInfoList(List<Tomb.PartnerTemp> list) {
        boolean isInit = false;
        if (this.partnerInfoMap.size() == 0) {
            isInit = true;
        }
        for (Tomb.PartnerTemp partnerTemp : list) {
            PartnerInfo partnerInfo = new PartnerInfo();
            partnerInfo.setId(partnerTemp.getId());
            partnerInfo.setAbility(partnerTemp.getBaseEarn());
            this.partnerInfoMap.put(partnerInfo.getId(), partnerInfo);
        }
        if (isInit) {
            this.hp = this.getTotalAttack();
            this.maxHp = this.getTotalHp();
        }
    }

    public PartnerInfo acquirePartnerInfo(int partnerId) {
        PartnerInfo partnerInfo = this.partnerInfoMap.get(partnerId);
        return partnerInfo;
    }

    public Map<Integer, PartnerUpgradeInfo> getPartnerUpgradeInfoMap() {
        return partnerUpgradeInfoMap;
    }

    public void setPartnerUpgradeInfoMap(Map<Integer, PartnerUpgradeInfo> partnerUpgradeInfoMap) {
        this.partnerUpgradeInfoMap = partnerUpgradeInfoMap;
    }


    public PartnerUpgradeInfo acquirePartnerUpgradeInfo(int partnerId) {
        PartnerUpgradeInfo partnerUpgradeInfo = this.partnerUpgradeInfoMap.get(partnerId);
        if (partnerUpgradeInfo == null) {
            partnerUpgradeInfo = new PartnerUpgradeInfo();
            partnerUpgradeInfo.setId(partnerId);
            this.partnerUpgradeInfoMap.put(partnerUpgradeInfo.getId(), partnerUpgradeInfo);
        }
        return partnerUpgradeInfo;
    }

    public int getFloor() {
        return floor;
    }

    public void setFloor(int floor) {
        this.floor = floor;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }


    public synchronized int getEnergy(ActivityTombConfig config) {
        int tomb_energy_cd = config.getTOMB_ENERGY_CD();
        int tomb_energy_limit = config.getTOMB_ENERGY_LIMIT();
        int tomb_energy_cd_num = config.getTOMB_ENERGY_CD_NUM();
        int energy = this.energy;
        if (energy >= tomb_energy_limit) {
            return energy;
        }
        long now = System.currentTimeMillis();

        long energyUpdateTime = this.getEnergyUpdateTime();
        if (energyUpdateTime == 0) {
            this.setEnergyUpdateTime(now);
            return energy;
        }
        if (!DateHelper.isSameDay(now/1000, this.getEnergyUpdateTime()/1000)) {
            int rawEnergy = this.energy;
            if (this.energy < tomb_energy_limit) {
                this.energy = tomb_energy_limit;
            }
            this.setEnergyUpdateTime(now);
            this.refreshUpdateTime();


            //发到游戏服写日志
            Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
            logBuilder.setLEnum(Tomb.GameTombLogEnum.ENERGY);
            logBuilder.setUserId(this.getUserId());
            logBuilder.setActivityId(this.getActivityId());
            logBuilder.setUnionUid(this.getUserInfo().getUnionUid());
            logBuilder.setFloor(this.getFloor());
            logBuilder.setX(this.getX());
            logBuilder.setY(this.getY());
            logBuilder.setHp(this.getHp());
            logBuilder.setTimestamp(now);
            Tomb.TombLogEnergy.Builder log = Tomb.TombLogEnergy.newBuilder();
            TombActivity tombActivity = TombServiceMgr.getActivity(this.getActivityId());
            log.setEnergyChange(this.energy - rawEnergy);
            log.setEnergy(this.energy);
            log.setEventId(0);
            log.setDescription(String.format("隔天重置，从%d到了%d", rawEnergy, this.energy));
            logBuilder.setEnergy(log);
            tombActivity.sendLogToGame(this, logBuilder);

            return this.energy;
        }

        long diff = now/1000 - energyUpdateTime/1000;
        long increase = diff / tomb_energy_cd;
        if (increase > 0) {
            int rawEnergy = energy;
            energy = energy + (int) increase * tomb_energy_cd_num;
            if (energy > tomb_energy_limit) {
                energy = tomb_energy_limit;
                energyUpdateTime = now;
            } else {
                energyUpdateTime = energyUpdateTime + (increase * tomb_energy_cd * 1000);
            }
            this.setEnergy(energy);
            this.setEnergyUpdateTime(energyUpdateTime);
            this.refreshUpdateTime();

            //发到游戏服写日志
            Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
            logBuilder.setLEnum(Tomb.GameTombLogEnum.ENERGY);
            logBuilder.setUserId(this.getUserId());
            logBuilder.setActivityId(this.getActivityId());
            logBuilder.setUnionUid(this.getUserInfo().getUnionUid());
            logBuilder.setFloor(this.getFloor());
            logBuilder.setX(this.getX());
            logBuilder.setY(this.getY());
            logBuilder.setHp(this.getHp());
            logBuilder.setTimestamp(now);
            Tomb.TombLogEnergy.Builder log = Tomb.TombLogEnergy.newBuilder();
            TombActivity tombActivity = TombServiceMgr.getActivity(this.getActivityId());
            log.setEnergyChange(this.energy - rawEnergy);
            log.setEnergy(this.energy);
            log.setDescription(String.format("冷却时间到了，从%d到了%d", rawEnergy, this.energy));
            logBuilder.setEnergy(log);
            tombActivity.sendLogToGame(this, logBuilder);


        }
        return this.energy;
    }

    public void setEnergy(int energy) {
        this.energy = energy;
    }

    public boolean costEnergy(int value, int eventId) {
        if (this.energy - value < 0) {
            return false;
        }
        int rawEnergy = this.energy;
        this.costEnergy = this.costEnergy + value;
        this.energy = this.energy - value;

        LocalDateTime now = LocalDateTime.now();
        //发到游戏服写日志
        Tomb.TombLogCrossToGameReq.Builder logBuilder = Tomb.TombLogCrossToGameReq.newBuilder();
        logBuilder.setLEnum(Tomb.GameTombLogEnum.ENERGY);
        logBuilder.setUserId(this.getUserId());
        logBuilder.setActivityId(this.getActivityId());
        logBuilder.setUnionUid(this.getUserInfo().getUnionUid());
        logBuilder.setFloor(this.getFloor());
        logBuilder.setX(this.getX());
        logBuilder.setY(this.getY());
        logBuilder.setHp(this.getHp());
        logBuilder.setTimestamp(now.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
        Tomb.TombLogEnergy.Builder log = Tomb.TombLogEnergy.newBuilder();
        TombActivity tombActivity = TombServiceMgr.getActivity(this.getActivityId());
        log.setEnergyChange(this.energy - rawEnergy);
        log.setEnergy(this.energy);
        log.setEventId(eventId);
        log.setDescription(String.format("消耗能力，从%d到了%d", rawEnergy, this.energy));
        logBuilder.setEnergy(log);
        tombActivity.sendLogToGame(this, logBuilder);

        return true;
    }

    public void addEnergy(int value) {
        this.energy = this.energy + value;
        return;
    }

    public long getHp() {
        if (this.hp < 0) {
            return 0;
        }
        return hp;
    }

    public void setHp(long hp) {
        this.hp = hp;
    }

    public long getMaxHp() {
        return maxHp;
    }

    public void setMaxHp(long maxHp) {
        this.maxHp = maxHp;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }


    public long getTotalAttack() {
        long total = 0;
        for (PartnerInfo partnerInfo : this.partnerInfoMap.values()) {
            PartnerUpgradeInfo partnerUpgradeInfo = this.acquirePartnerUpgradeInfo(partnerInfo.getId());
            long resultAbility = partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility());
            total = total + resultAbility;
        }

        total = (long) ((double) total * (1 + (double) this.getAttackAddition() / 1000));
        return total;
    }

    public long getTotalAttackWithoutAddition(){
        long total = 0;
        for (PartnerInfo partnerInfo : this.partnerInfoMap.values()) {
            PartnerUpgradeInfo partnerUpgradeInfo = this.acquirePartnerUpgradeInfo(partnerInfo.getId());
            long resultAbility = partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility());
            total = total + resultAbility;
        }
        return total;
    }

    public long getTotalHp() {
        long total = 0;
        for (PartnerInfo partnerInfo : this.partnerInfoMap.values()) {
            PartnerUpgradeInfo partnerUpgradeInfo = this.acquirePartnerUpgradeInfo(partnerInfo.getId());
            long resultAbility = partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility());
            total = total + resultAbility;
        }

        total = (long) ((double) total * (1 + (double) this.getHpAddition() / 1000));
        return total;
    }

    public long getTotalHpWithoutAddition(){
        long total = 0;
        for (PartnerInfo partnerInfo : this.partnerInfoMap.values()) {
            PartnerUpgradeInfo partnerUpgradeInfo = this.acquirePartnerUpgradeInfo(partnerInfo.getId());
            long resultAbility = partnerUpgradeInfo.getResultAbility(partnerInfo.getAbility());
            total = total + resultAbility;
        }

        return total;
    }

    public long getEnergyUpdateTime() {
        return energyUpdateTime;
    }

    public void setEnergyUpdateTime(long energyUpdateTime) {
        this.energyUpdateTime = energyUpdateTime;
    }

    public String getPositionKey() {
        return String.format("%d_%d", this.x, this.y);
    }


    public int getGoDownstairs() {
        return goDownstairs;
    }

    public void setGoDownstairs(int goDownstairs) {
        this.goDownstairs = goDownstairs;
    }

    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }


    public boolean isFullHp() {
        if (this.getHp() >= this.getMaxHp()) {
            return true;
        }
        return false;
    }
    public Tomb.TombEventUserInfoTemp.Builder toEventUserInfoBuilder() {
        Tomb.TombEventUserInfoTemp.Builder eventUserInfoBuilder = Tomb.TombEventUserInfoTemp.newBuilder();
        eventUserInfoBuilder.setUserId(this.getUserId());
        eventUserInfoBuilder.setNickname(this.getUserInfo().getNickName());
        eventUserInfoBuilder.setDecoration(this.getUserInfo().getDecoration());
        eventUserInfoBuilder.setServerId(this.getUserInfo().getServerId());
        eventUserInfoBuilder.setTitleId(this.getUserInfo().getTitleId());
        eventUserInfoBuilder.setVipExp(this.getUserInfo().getVipExp());
        eventUserInfoBuilder.setHideVipAddress(this.getUserInfo().getHideVipAndAddress());
        eventUserInfoBuilder.setCity(this.getUserInfo().getCity());
        eventUserInfoBuilder.setUnionUid(this.getUserInfo().getUnionUid());
        return eventUserInfoBuilder;
    }

    public Tomb.TombPVPUserInfoTemp.Builder toPvpUserInfoTempBuilder() {
        Tomb.TombPVPUserInfoTemp.Builder temp = Tomb.TombPVPUserInfoTemp.newBuilder();
        UserInfo info = this.getUserInfo();
        temp.setId(this.getUserId());
        temp.setNickname(info.getNickName());
        temp.setUserId(this.getUserId());
        temp.setDecoration(info.getDecoration());
        temp.setServerId(info.getServerId());
        temp.setUnionName(info.getUnionName());
        temp.setUnionAliasId(info.getUnionAliasId());
        temp.setRewardScore(this.getRewardScore());
        temp.setSex(info.getSex());
        temp.setDollId(this.getDollId());
        return temp;
    }

    public int getRewardScore() {
        return rewardScore;
    }

    public void setRewardScore(int rewardScore) {
        this.rewardScore = rewardScore;
    }

    public void addRewardScore(int rewardScore) {
        this.rewardScore = this.rewardScore + rewardScore;
    }

    public int getPvpChoseNum() {
        return pvpChoseNum;
    }

    public void setPvpChoseNum(int pvpChoseNum) {
        this.pvpChoseNum = pvpChoseNum;
    }

    public void addPvpChoseNum(int num) {
        this.pvpChoseNum = this.pvpChoseNum + num;
    }

    public long getAttackUserId() {
        return attackUserId;
    }

    public void setAttackUserId(long attackUserId) {
        this.attackUserId = attackUserId;
    }

    public long getScore() {
        return score;
    }

    public void setScore(long score) {
        this.score = score;
    }

    public void addScore(long score) {
        this.score = this.score + score;
    }

    public void addUnionScore(long score) {
        this.unionScore = this.unionScore + score;
    }

    public long getUserNianTuNum() {
        return userNianTuNum;
    }

    public void setUserNianTuNum(long userNianTuNum) {
        this.userNianTuNum = userNianTuNum;
    }


    public int getMultiKill() {
        return multiKill;
    }

    public void setMultiKill(int multiKill) {
        this.multiKill = multiKill;
    }

    public void addMultiKill(int multiKill) {
        this.multiKill = this.multiKill + multiKill;
    }


    public String getLockEvent() {
        return lockEvent;
    }

    public void setLockEvent(String lockEvent) {
        this.lockEvent = lockEvent;
    }

    public boolean isAlive() {
        if (this.hp <= 0) {
            return false;
        }
        return true;
    }

    public long underAttack(long attack) {
        long realAttack = this.hp;
        this.hp = this.hp - attack;
        if (this.hp <= 0) {
            this.hp = 0;
            return realAttack;
        }
        return attack;
    }

    public long getUnionScore() {
        return unionScore;
    }

    public void setUnionScore(long unionScore) {
        this.unionScore = unionScore;
    }


    public Set<String> getPvpUnionChooseMap() {
        return pvpUnionChooseMap;
    }

    public void setPvpUnionChooseMap(Set<String> pvpUnionChooseMap) {
        this.pvpUnionChooseMap = pvpUnionChooseMap;
    }

    public Tomb.PlayerBaseTempMsg.Builder toPlayerBaseTempBuilder() {
        Tomb.PlayerBaseTempMsg.Builder builder = Tomb.PlayerBaseTempMsg.newBuilder();
        UserInfo info = this.userInfo;
        builder.setUserAliasId(info.getUserAliasId());
        builder.setNickName(info.getNickName());
        builder.setTitleId(info.getTitleId());
        builder.setDecoration(info.getDecoration());
        builder.setUnionName(info.getUnionName());
        builder.setUnionUid(info.getUnionUid());
        builder.setUnionAliasId(info.getUnionAliasId());
        builder.setVipExp(info.getVipExp());
        builder.setSex(info.getSex());
        builder.setEarnSpeed(info.getEarnSpeed());
        builder.setRegisterTime(info.getRegisterTime());
        builder.setServerId(info.getServerId());
        builder.setWorld(info.getWorld());
        builder.setContinent(info.getContinent());
        builder.setCountry(info.getCountry());
        builder.setProvince(info.getProvince());
        builder.setCity(info.getCity());
        builder.setLastLoginTime(info.getLastLoginTime());
        builder.setPrestige(info.getPrestige());
        builder.setHideVipAndAddress(info.getHideVipAndAddress());
        builder.setTotalAbility(info.getTotalAbility());
        builder.setTotalIntimacy(info.getTotalIntimacy());
        builder.setUnionHonerPoint(info.getUnionHonerPoint());
        builder.setBadge(info.getBadge());
        return builder;
    }

    public Map<Integer, Long> getDollMap() {
        return dollMap;
    }

    public void setDollMap(Map<Integer, Long> dollMap) {
        this.dollMap = dollMap;
    }

    public int getDollId() {
        return dollId;
    }

    public void setDollId(int dollId) {
        this.dollId = dollId;
    }

    public int getAttackAddition() {
        return attackAddition;
    }

    public void setAttackAddition(int attackAddition) {
        this.attackAddition = attackAddition;
    }

    public int getHpAddition() {
        return hpAddition;
    }

    public void setHpAddition(int hpAddition) {
        this.hpAddition = hpAddition;
    }

    public int getCostEnergy() {
        return costEnergy;
    }

    public void setCostEnergy(int costEnergy) {
        this.costEnergy = costEnergy;
    }

    public Tomb.UserInfo.Builder toUserInfoBuilder(ActivityTombConfig config) {
        Tomb.UserInfo.Builder userInfoBuilder = Tomb.UserInfo.newBuilder();
        userInfoBuilder.setEnergy(this.getEnergy(config));
        userInfoBuilder.setHp(this.getHp());
        userInfoBuilder.setMaxHp(this.getMaxHp());
        userInfoBuilder.setAttack(this.getTotalAttack());
        userInfoBuilder.setUserId(this.getUserId());
        userInfoBuilder.setRewardScore(this.getRewardScore());
        userInfoBuilder.setPersonalScore(this.getScore());
        userInfoBuilder.setUnionScore(this.getUnionScore());
        userInfoBuilder.setEnergyLastTime(this.getEnergyUpdateTime());
        userInfoBuilder.setAssistTimes(this.getAssistTimes());
        return userInfoBuilder;
    }

    public int getEnergy() {
        return energy;
    }

    public List<Integer> getSwitchList() {
        return switchList;
    }

    public void setSwitchList(List<Integer> switchList) {
        this.switchList = switchList;
    }

    public int getGuideMark() {
        return guideMark;
    }

    public void setGuideMark(int guideMark) {
        this.guideMark = guideMark;
    }


    public Tomb.AllyInfo.Builder toAllyInfoBuilder() {
        Tomb.AllyInfo.Builder allyInfoBuilder = Tomb.AllyInfo.newBuilder();
        allyInfoBuilder.setCoordinate(Tomb.CoordinateTemp.newBuilder().setRow(this.getX()).setColumn(this.getY()).setFloor(this.getFloor()));
        allyInfoBuilder.setUserId(this.getUserId());
        allyInfoBuilder.setName(this.getUserInfo().getNickName());
        allyInfoBuilder.setPersonalScore(this.getScore());
        allyInfoBuilder.setUnionScore(this.getUnionScore());
        allyInfoBuilder.setIsDead(this.getStatus() == 2);
        allyInfoBuilder.setIsInTrap(this.getStatus() == 1);
        allyInfoBuilder.setDollId(this.getDollId());
        allyInfoBuilder.setSex(this.getUserInfo().getSex());
        allyInfoBuilder.setUnionUid(this.getUserInfo().getUnionUid());
        return allyInfoBuilder;
    }

    public int getAssistTimes() {
        return assistTimes;
    }

    public void setAssistTimes(int assistTimes) {
        this.assistTimes = assistTimes;
    }

    public int getExploredNum() {
        return exploredNum;
    }

    public void setExploredNum(int exploredNum) {
        this.exploredNum = exploredNum;
    }

    /**
     * 获取打理开关状态。开关类型。
     * @param type
     * @return
     */
    public boolean getSwitchByUserAndType(int type) {
        if (switchList != null && switchList.size() > 0) {
            for (int switchType : switchList) {
                if (type == switchType) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 获取战力最高的门客。根据门客IDS
     * @param partnerIds
     * @return
     */
    public PartnerInfo getMaxAbilityPartnerInfoByIdList(Set<Integer> partnerIds) {
        PartnerInfo maxPartner = null;
        for (Integer partnerId : partnerIds) {
            PartnerInfo partnerInfo = partnerInfoMap.get(partnerId);
            if (maxPartner == null) {
                maxPartner = partnerInfo;
            } else {
                if (partnerInfo.getAbility() > maxPartner.getAbility()) {
                    maxPartner = partnerInfo;
                }
            }
        }
        return maxPartner;
    }
    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        if(this.groupId != groupId) {
            this.groupId = groupId;
            setUpdateOption();
        }
    }
}
